#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>
#include <sstream>
#include <memory>



int main()
{
    //反序列化
    std::string json_string = "{\"name\":\"全部\", \"age\":30, \"city\":\"北京\"}";

    Json::Value root;
    Json::Reader reader;

    bool ok = reader.parse(json_string, root);
    (void)ok;

    //把序列化字符串，反序列化到了Json::Value里面
    std::string name = root["name"].asString();
    int age = root["age"].asInt();
    std::string city = root["city"].asString();

    std::cout << name << std::endl;
    std::cout << age << std::endl;
    std::cout << city << std::endl;



    // Json::Value root;
    // root["name"] = "大笨蛋";
    // root["sex"] = "男";
    // root["age"] = 66;
    
    // Json::StreamWriterBuilder sbuilder;
    // std::unique_ptr<Json::StreamWriter> writer(sbuilder.newStreamWriter());
    // std::stringstream ss;
    // writer->write(root, &ss);
    // std::string s = ss.str();
    // std::cout << s << std::endl;

    //去掉换行，网络传送的数据量就小了
    // Json::FastWriter writer;

    //用\n给我们进行按行设置了，可读性比较好
    //Json::StyledStreamWriter writer;
    // std::string s = writer.write(root);
    // std::cout << s << std::endl;

    // Json::Value sub;
    // sub["tel"] = "123456";
    // sub["地址"] = "可达";

    // root["info"] = sub;

    // std::string s = root.toStyledString();
    // std::cout << s << std::endl;

    // std::cout << "你好" << std::endl;
    return 0;
}